package com.megalith.controller;

import com.megalith.dto.ManagerVerifyDTO;
import com.megalith.dto.StaffApplyDTO;
import com.megalith.dto.StaffLeaveTicketDTO;
import com.megalith.service.ListenerTaskService;
import com.megalith.utils.RequestResponseUtil;
import com.megalith.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description 任务监听器，接口管理
 * @Author lfp
 * @Date 2022/7/17
 * @Version 1.0
 */
@RestController
@Api(tags = "任务监听器，接口管理")
@RequestMapping("listener")
public class ListenerTaskController {

    @Autowired
    private ListenerTaskService listenerTaskService;

    /**
     *@Description 启动带监听器的流程
     *@Author lfp
     *@Date 2022/7/17
     *@param applyDTO
     *@param result
     *@Return
     */
    @ApiOperation(value = "启动带监听器的流程")
    @PostMapping("process/start")
    public Result startListenerProcess(@Validated @RequestBody StaffApplyDTO applyDTO, BindingResult result){
        if (result.hasErrors()) {
            return RequestResponseUtil.doBindingResultHandel(result);
        }else {
            return Result.ok(listenerTaskService.startListenerProcess(applyDTO));
        }
    }

    @ApiOperation(value = "员工填写请假单")
    @PostMapping("task/ticket/fill")
    public Result fillListenerTaskTicket(@Validated @RequestBody StaffLeaveTicketDTO leaveTicketDTO, BindingResult result){
        if (result.hasErrors()) {
            return RequestResponseUtil.doBindingResultHandel(result);
        }else {
            return listenerTaskService.fillListenerTaskTicket(leaveTicketDTO);
        }
    }


    @ApiOperation(value = "经理处理个人任务")
    @PostMapping("manager/complete")
    public Result completeManagerTask(@Validated @RequestBody ManagerVerifyDTO verifyDTO, BindingResult result){
        if (result.hasErrors()) {
            return RequestResponseUtil.doBindingResultHandel(result);
        }else {
            return listenerTaskService.completeManagerTask(verifyDTO);
        }
    }


    //todo 触发监听任务  分类型
}
